lobsterlayui.main(['index', 'layer', 'form', 'element', 'table', 'laydate'], {
    data: {
        datatable: null,
        replyWin: 0,
    },
    pageload: function (right) {
        console.log(right);
        this.loadData();
        this.initevent();
    },
    loadData() {
        let self = this;

        //表格渲染
        self.data.datatable = layui.table.render({
            elem: '#datatable'
            , headers: lobsterh5.GetHeaderData()
            , where: {
                searchkey: $("#searchkey").val() || '',
                status: $("#cmbStatus").find("option:selected").val()
            }
            , height: 'full-120'
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度
            , url: lobsterh5.GetLowCodeUrl('tsevaluation.getevaluationpage') //数据接口
            , page: true //开启分页
            //, size: 'sm'
            //, even: true
            , cols: [[ //表头
                { field: 'ID', title: '编号', align: 'center', width: "100", sort: true }
                , { field: 'DocName', title: '医生姓名', width: "140" }
                , { field: 'Satisfaction', title: '满意度', align: 'center', width: "100" }
                , { field: 'EvaluateContent', title: '评价内容', width: "200" }
                , { field: 'EvaluateTime', title: '评价时间', width: "180", sort: true }
                , { field: 'OrderNo', title: '订单号', width: "200" }
                , { field: 'PatName', title: '就诊人', width: "100" }
                , { field: 'StatusName', title: '状态', width: "100", align: 'center', sort: true, templet: '#flagTpl' }
                , { field: 'OperateTime', title: '操作时间', width: "180", templet: '#optimeTpl' }
                , { field: 'ReplyContent', title: '回复内容', width: '200' }
                , { field: 'ReplyTime', title: '回复时间', align: 'center', width: '180', templet: '#replytimeTpl' }
                , { title: '操作', width: "180", fixed: 'right', toolbar: '#bar', align: 'left' }
            ]],
            parseData: function (res) {
                return {
                    code: res.code,
                    msg: res.msg,
                    count: res.data.count,
                    data: res.data.data
                }
            }
        });
    },
    initevent() {
        var self = this;
        //查找
        layui.form.on('submit(LAY-app-front-search)', function (data) {
            self.data.datatable.reload({
                where: {
                    searchkey: $("#searchkey").val() || '',
                    status: $("#cmbStatus").find("option:selected").val()
                }
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //监听回复评价提交
        layui.form.on('submit(LAY-reply-form-submit)', function (data) {
            var field = data.field; //获取提交的字段
            console.log(field);
            lobsterlayui.POSTAPI('tsevaluation.savereplycontent', field).then(retdata => {
                layer.msg("回复成功");
                self.data.datatable.reload();//数据刷新
                $("#LAY-repy-form-reset").trigger('click');
                layer.close(self.data.replyWin); //关闭弹层
            })
        });

        //监听行工具栏事件（编辑、启停用）
        layui.table.on('tool(datatable)', function (obj) {
            var data = obj.data;//当前行数据
            var tr = obj.tr;
            var layEvent = obj.event;//获得lay-event的值
            switch (layEvent) {
                case 'setflag':
                    var msg = data.Status == 0 ? "发布" : "取消发布";
                    var status = (data.Status == 0 ? 1 : 0);
                    layer.confirm('确认' + msg + '吗？', { icon: 3, title: '提示' }, function (index) {

                        lobsterlayui.GETAPI('tsevaluation.stopevaluation', { id: data.ID, status: status }).then(retdata => {
                            layer.msg(msg + "成功");
                            self.data.datatable.reload();//数据刷新
                        })

                        layer.close(index);
                    }, function () { tr.removeAttr("class"); });
                    break;
                case 'reply':
                    self.data.replyWin = layer.open({
                        type: 1
                        , title: '回复评价'
                        , maxmin: true
                        , content: $('#layuiadmin-form-reply')
                        , area: ['500px', '320px']
                        , btn: ['保存', '取消']
                        , resize: false
                        , success: function (layero, index) {
                            setTimeout(function () {
                                $("#id").val(data.ID);
                            }, 300);
                        }
                        , btn2: function (index, layero) {
                            $("#LAY-repy-form-reset").trigger('click');
                        }
                        , cancel: function () {
                            $("#LAY-repy-form-reset").trigger('click');
                        }
                        , yes: function (index, layero) {
                            $("#LAY-reply-form-submit").trigger('click');
                        }
                    });
                    break;
                case 'delreplycontent':
                    layer.confirm('确认删除回复内容吗？', { icon: 3, title: '提示' }, function (index) {
                        lobsterlayui.GETAPI('tsevaluation.deletereplycontent', { ID: data.ID }).then(retdata => {
                            layer.msg("操作成功");
                            self.data.datatable.reload();//数据刷新
                        })

                        layer.close(index);
                    }, function () { tr.removeAttr("class"); });
                    break;
            };
        });

    },

});